home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / shells / kiss-0.11 / kiss-0 / kiss / src / parser < prev    next >
Text File  |  1995-03-23  |  3KB  |  200 lines

  1. /* parser definition */
  2.  
  3. /* normal C code */
  4. %{
  5. #include "kiss.h"
  6. #define YYSTYPE Stringstack
  7.  
  8. static Stringstack
  9.     tmp;
  10. %}
  11.  
  12. /* token section */
  13. %token IDENT SQUOTESTRING DQUOTESTRING ENDLINE VARIABLE
  14.        PIPETO BACKGROUND REDIRTO REDIRFROM REDIRAPPEND
  15.        RECALLCMD BQUOTESTRING
  16.  
  17. /* rules */
  18. %%
  19. input:
  20.     input    
  21.     line        {
  22.             dumpstack ("whole line:", $2);
  23.             runcmd ($2);
  24.             clearstack (&$2);
  25.             while (bufferedinput [0])
  26.             {
  27.                 addstringtostack (&$2, bufferedinput);
  28.                 bufferedinput [0] = '\0';
  29.                 runcmd ($2);
  30.                 clearstack (&$2);
  31.             }
  32.             inputparsed = 1;
  33.             }
  34.     |
  35.     line        {
  36.             dumpstack ("whole line", $1);
  37.             runcmd ($1);
  38.             clearstack (&$1);
  39.             while (bufferedinput [0])
  40.             {
  41.                 addstringtostack (&$1, bufferedinput);
  42.                 bufferedinput [0] = '\0';
  43.                 runcmd ($1);
  44.                 clearstack (&$1);
  45.             }
  46.             inputparsed = 1;
  47.             }
  48.     ;
  49.  
  50. line:
  51.     oneline
  52.     optbackground
  53.     endlinetoken    {
  54.             $$ = addstring ($1, $2);
  55.             }
  56.     |
  57.     endlinetoken
  58.     |
  59.     error
  60.     endlinetoken
  61.     ;
  62.  
  63. oneline:
  64.     oneline
  65.     pipetotoken
  66.     statement        {
  67.             tmp = addstring ($1, $2);
  68.             $$ = addstring (tmp, $3);
  69.             }
  70.     |
  71.     statement
  72.     ;
  73.             
  74. statement:
  75.     recalltoken
  76.     command        {
  77.             $$ = addstring ($1, $2);
  78.             dumpstack ("recallcmd:", $$);
  79.             }
  80.     |
  81.     command
  82.     optredir        {
  83.             $$ = addstring ($1, $2);
  84.             dumpstack ("statement:", $$);
  85.             }
  86.     ;
  87.  
  88. command:
  89.     command
  90.     string        {
  91.             $$ = addstring ($1, $2);
  92.             dumpstack ("command:" , $$);
  93.             }
  94.     |
  95.     string        { dumpstack ("command:", $$); }
  96.     ;
  97.  
  98. optredir:
  99.     redirto
  100.     |
  101.     redirfrom
  102.     |
  103.     redirto
  104.     redirfrom        {
  105.             $$ = addstring ($1, $2);
  106.             }
  107.     |
  108.     redirfrom
  109.     redirto          {
  110.             $$ = addstring ($1, $2);
  111.             }
  112.     |
  113.     /* empty */        { $$.nstr = 0; }
  114.     ;
  115.  
  116. optbackground:
  117.     backgroundtoken
  118.     |
  119.     /* empty */        { $$.nstr = 0; }
  120.     ;
  121.  
  122. redirto:
  123.     redirtotoken
  124.     string        {
  125.             $$ = addstring ($1, $2);
  126.             }
  127.    |
  128.     redirappendtoken
  129.     string        {
  130.             $$ = addstring ($1, $2);
  131.             }
  132.    ;
  133.  
  134. redirfrom:
  135.     redirfromtoken
  136.     string        {
  137.             $$ = addstring ($1, $2);
  138.             }
  139.     ;
  140.     
  141. string:
  142.     simplestring
  143.     |
  144.     dquotestring
  145.     |
  146.     bquotestring
  147.     |
  148.     squotestring
  149.     |
  150.     variable
  151.     ;
  152.  
  153. simplestring:
  154.     IDENT        { $$ = setstring (yytext); }
  155.     ;
  156.  
  157. dquotestring:
  158.     DQUOTESTRING    { $$ = setquotedstring (yytext, '"'); }
  159.     ;
  160.  
  161. squotestring:
  162.     SQUOTESTRING    { $$ = setquotedstring (yytext, '\''); }
  163.     ;
  164.  
  165. bquotestring:
  166.     BQUOTESTRING    { $$ = setstring (yytext); }
  167.     ;
  168.  
  169. variable:
  170.     VARIABLE        { $$ = setvariable (yytext); }
  171.     ;
  172.  
  173. redirtotoken:
  174.     REDIRTO        { $$ = setstring (">"); }
  175.     ;
  176.  
  177. redirappendtoken:
  178.     REDIRAPPEND        { $$ = setstring (">>"); }
  179.     ;
  180.     
  181. redirfromtoken:
  182.     REDIRFROM        { $$ = setstring ("<"); }
  183.     ;
  184.  
  185. pipetotoken:
  186.     PIPETO        { $$ = setstring ("|"); }
  187.     ;
  188.  
  189. backgroundtoken:
  190.     BACKGROUND        { $$ = setstring ("&"); }
  191.     ;
  192.  
  193. endlinetoken:
  194.     ENDLINE        { $$.nstr = 0; }
  195.     ;
  196.  
  197. recalltoken:
  198.     RECALLCMD        { $$ = setstring ("!"); }
  199.     ;
  200.